var topOrgCentrex;
var topOrgCentrey;
$(function () {
    $.ajax({
        type: 'get',
        url: '/organization/data/list',
        dataType: 'html',
        async: false,
        success: function (data) {
            var data = JSON.parse(data);
            topOrgCentrex = data[0].centrex;
    		topOrgCentrey = data[0].centrey;
    		
            for (var i = 0; i < data.length; i++) {
                var dataId = data[i].orgid;
                if (i==0) {
                    $('.sidebar-menu').append('<li class="treeview" id="firstOrg' + dataId + '" orgid=' + dataId + ' lan=' + data[i].centrex + ' lon=' + data[i].centrey + '><a class="Org" href="#"><i class="fa  fa-map-marker"></i><span> '+ data[i].orgName + ' </span><span class="pull-right-container addPull1"></span></a><ul class="treeview-menu"></ul></li>')
                } else{//&& !data[i].parent.parent
                    $("#firstOrg" + data[i].parent.orgid + ">ul").append('<li id="firstOrg' +dataId + '" orgid=' + dataId + ' lan = ' + data[i].centrex + ' lon = ' + data[i].centrey+ '><a class="Org orgSelected" href="#"><i class="fa fa-circle-o"></i><span id="secondOrg"> ' + data[i].orgName + ' </span><span class="pull-right-container addPull2"></span></a><ul class="treeview-menu"></ul></li>');
                    $("#firstOrg" + data[i].parent.orgid+" .addPull1").html('<i class="fa fa-angle-left pull-right"></i>');
                } 
            }
    		
        }
    });
//    $(".Org ul").each(function (){
//    	console.log($(this).html())
//    	if(!$(this).html()){
//    		$(this).remove();
//    	}
//    })
// 点击组织列表选中组织显示圆圈
    $(".orgSelected").on("click",function(){
    	$(".sidebar-menu .orgSelected .fa").removeClass("fa-circle").addClass("fa-circle-o");
    	$(this).find("i").removeClass("fa-circle-o").addClass("fa-circle");
    	$(".orgSelected").removeClass("orgSelectedStyle");
    	$(this).addClass("orgSelectedStyle");
    });
	//点击组织树，移动地图位置到组织的经纬度
	$(".sidebar-menu").on('click','.Org',function(){
		if(!$(this).siblings("ul").html()){
			$(this).siblings("ul").remove();
		}
		var obj = $(this);
		var orgid = obj.parent().attr("orgid");
		var lan = obj.parent().attr("lan");
		var lon = obj.parent().attr("lon");
		BaiDuMap.panTo(lan,lon);
	});
	/*显示用户信息下面的时间*/
	$(".main-sidebar .text-muted").text(moment().format('YYYY-MM-DD HH:mm:ss'));
	setInterval(function (){
		$(".main-sidebar .text-muted").text(moment().format('YYYY-MM-DD HH:mm:ss'));
	},1000);

	
});
